package com.xingfly.school.student.domain;

import lombok.Data;
import lombok.EqualsAndHashCode;

import javax.persistence.*;
import java.time.LocalDateTime;

/**
 * 学生课程注册信息聚合根
 * Created by SuperS on 2020/3/25.
 *
 * @author SuperS
 */
@Data
@Entity
@EqualsAndHashCode
@Table(name = "ddd_course_registration", uniqueConstraints = {
        @UniqueConstraint(columnNames = {"student_id", "course_id"}, name = "student_course_unique"),
})
public class StudentCourseRegistration {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @Column(name = "student_id")
    private Long studentId;

    @Column(name = "course_id")
    private Long courseId;

    public StudentCourseRegistration() {
    }

    private LocalDateTime registrationTime;

    public StudentCourseRegistration(Long studentId, Long courseId) {
        this.studentId = studentId;
        this.courseId = courseId;
        this.registrationTime = LocalDateTime.now();
    }

    public static StudentCourseRegistration of(Long studentId, Long courseId) {
        return new StudentCourseRegistration(studentId, courseId);
    }
}
